﻿Imports ICSharpCode.SharpZipLib.Zip
Imports ICSharpCode.SharpZipLib.Core





Public Class Form1

    Dim strPath As String = Application.StartupPath

    Dim filePath As String
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim replace As String = """id"":""1.6.2,"""
        Dim withreplace As String = """id"":""1.6.2_Dawnpack,"""
        Dim temp As String = "C:/temp/privatemodding"
        Dim filepath2 As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.Dawnpack\"

        filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\mods"
        'My.Computer.Network.DownloadFile("http://newauroradev.heliohost.org/Noahp78/Ionic.Zip.dll", strPath)
        Dim filefilter As String = vbNull

        Label3.Text = ("Downloading Modpack and other file's needed")

        DownloadFile("http://newauroradev.heliohost.org/Dawnpack/Dawn%20Modpack.zip", "C:/temp/latest.zip")
        DownloadFile("http://files.minecraftforge.net/minecraftforge/minecraftforge-universal-1.6.2-9.10.0.835.jar", "C:/temp/forge.zip")
        'My.Computer.Network.DownloadFile("http://newauroradev.heliohost.org/Dawnpack/Dawn%20Modpack.zip", "C:/temp/latest.zip")
        'My.Computer.Network.DownloadFile("http://files.minecraftforge.net/minecraftforge/minecraftforge-universal-latest.jar", "C:/temp/forge.zip")

        Label3.Text = ("Doing modded MC magic!")
        'renamefolder(TextBox1.Text & "/Versions/1.6.2", "1.6.2_Dawnpack")
        'renamefile(TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2.jar", "1.6.2_Dawnpack.jar")
        ''renamefile(TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2.json", "1.6.2_Dawnpack.json")
        ''Replacer is bugged, Downloading right Version of Dawnpack.json
        'DownloadFile("http://newauroradev.heliohost.org/Dawnpack/1.6.2_Dawnpack.json", TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2_Dawnpack.json")
        ''replacer(TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2_Dawnpack.json", replace, withreplace)
        'Label3.Text = ("Making Temp Modding envirnoment for me (only for me!")
        ''Extract(TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2_Dawnpack.jar", "C:\temp/privatemodding/")
        '' renamefile(TextBox1.Text & "\Versions\1.6.2_Dawnpack\1.6.2_Dawnpack.jar", "1.6.2_Dawnpack.zip")
        ''ZipFile.ExtractToDirectory(TextBox1.Text & "\Versions\1.6.2_Dawnpack\1.6.2_Dawnpack.zip", "C:\temp\privatemodding\*")
        Dim fz As New FastZip()

        'fz.ExtractZip(TextBox1.Text & "\Versions\1.6.2_Dawnpack\1.6.2_Dawnpack.jar", "C:\temp\privatemodding\", filefilter)
        ''Using zip As ZipFile = ZipFile.Read(TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2_Dawnpack.jar")
        ''    zip.ExtractAll("C:\temp/privatemodding")
        'Label3.Text = ("Sleeping While waiting for Extraction to Finish :) 30secs")
        'Threading.Thread.Sleep(30000)
        ''End Using
        ''        Using zip As ZipFile = ZipFile.Read("C:\temp/download/mari0.zip")
        ''zip.ExtractAll("C:\temp\mari0")
        ''End Using
        DownloadFile("http://files.minecraftforge.net/minecraftforge/minecraftforge-installer-1.6.2-9.10.0.835.jar", "C:/temp/forgesetup.jar")
        Shell("java.exe -jar C:/temp/forgesetup.jar")
        Label3.Text = ("Please install forge using the installer because my method is broken...")
        System.Threading.Thread.Sleep(10000)


        'Label3.Text = ("Adding MC FORGE! (because it's freaking awesome and everything needs it...:(")
        ''Extract("C:\temp/forge.zip", "C:/temp/privatemodding/")
        ''Using zip As ZipFile = ZipFile.Read("c:\temp/forge.zip")
        ''    zip.ExtractAll(temp)
        ''End Using
        ''ZipFile.ExtractToDirectory("c:\temp\forge.zip", "C:\temp/privatemodding")
        'fz.ExtractZip("c:\temp\forge.zip", "C:\temp\ForgeModding", filefilter)
        ''renamefolder("C:\temp\ForgeModding", "C:/temp/privatemodding/")
        'Label3.Text = ("Sleeping once again... (LAZY PC!")
        'Threading.Thread.Sleep(6000)
        'My.Computer.FileSystem.CopyDirectory("C:\temp\ForgeModding", "C:/temp/privatemodding/", True)
        'Label3.Text = ("Sleeping before Creation of modded .jar")
        'Threading.Thread.Sleep(8000)
        'createZIP()
        'Threading.Thread.Sleep(10000)
        'movefile("c:\temp\1.6.2_Dawnpack.jar", TextBox1.Text & "/Versions/1.6.2_Dawnpack/1.6.2_Dawnpack.jar")
        ''Extract("C:\temp/latest.zip", filePath)
        ''Using zip As ZipFile = ZipFile.Read("c:/temp/latest.zip")
        ''    zip.ExtractAll(filePath)
        ''End Using
        ''ZipFile.ExtractToDirectory("C:\temp/latest.zip", TextBox1.Text & "/mods")
        fz.ExtractZip("C:\temp\latest.zip", TextBox1.Text & "/", filefilter)

        MessageBox.Show("Open the launcher and choose the profile Forge!")



    End Sub

    Function DownloadFile(ByRef URL As String, ByRef DestinationPath As String)

        My.Computer.Network.DownloadFile(URL, DestinationPath, vbNullString, vbNullString, True, 50000, True)

    End Function
    Private Function readfile(ByVal file As String)

        Dim fileReader As String
        fileReader = My.Computer.FileSystem.ReadAllText(file,
           System.Text.Encoding.UTF32)
        Return fileReader
    End Function
    Private Function replacer(ByVal file As String, ByVal string1 As String, ByVal string2 As String)
        Dim myStreamReaderL1 As System.IO.StreamReader
        Dim myStream As System.IO.StreamWriter

        Dim myStr As String
        myStreamReaderL1 = System.IO.File.OpenText(file)
        myStr = myStreamReaderL1.ReadToEnd()
        myStreamReaderL1.Close()


        myStr = myStr.Replace(string1, string2)
        'Save myStr
        myStream = System.IO.File.CreateText(file)
        myStream.WriteLine(myStr)
        myStream.Close()
    End Function
    Public Function renamefolder(ByVal folder As String, ByVal newname As String)
        My.Computer.FileSystem.RenameDirectory(folder, _
newname)
    End Function
    Public Function renamefile(ByVal file As String, ByVal newname As String)
        My.Computer.FileSystem.RenameFile(file, newname)
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        filePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft"
        TextBox1.Text = filePath
        DownloadFile("http://newauroradev.heliohost.org/Dawnpack/ICSharpCode.SharpZipLib.dll", strPath & "\ICSharpCode.SharpZipLib.dll")
    End Sub
    Private Sub createZIP()
        'Using zip As New ZipFile()
        '    '' add all those files to the ProjectX folder in the zip file
        '    zip.AddDirectory("C:/temp/privatemodding", "")
        '    zip.Save("C:/temp/1.6.2_Dawnpack.jar")
        Dim fz2 As New FastZip()
        fz2.CreateZip("C:\temp\privatemodding\", "c:\temp/1.6.2_Dawnpack.jar", True, vbNull)

        'ZipFile.CreateFromDirectory("C:\Temp\privatemodding", "c:\temp/1.6.2_Dawnpack.jar", CompressionLevel.Optimal, True)



    End Sub
    Private Function movefile(ByVal file As String, ByVal endlocation As String)
        My.Computer.FileSystem.MoveFile(file,
    endlocation)
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()

    End Sub
End Class
